package drds.configuration.db.xml_mapping.dynamic_tag.tag;

import drds.configuration.db.xml_mapping.dynamic_tag.tag_context.TagContext;

import java.util.List;


public class ChooseTag implements Tag {
    private final List<Tag> whenTagList;
    private final Tag otherwiseTag;

    public ChooseTag(List<Tag> whenTagList, Tag otherwiseTag) {
        this.whenTagList = whenTagList;
        this.otherwiseTag = otherwiseTag;
    }

    @Override
    public boolean apply(TagContext tagContext) {
        for (Tag whenTag : whenTagList) {//if tag
            if (whenTag.apply(tagContext)) {
                return true;
            }
        }
        if (otherwiseTag != null) {
            otherwiseTag.apply(tagContext);
            return true;
        }
        return false;
    }
}
